package com.insleton.admin.employee.controller;

import com.cyyz.tai.service.PointService;
import com.google.common.collect.Lists;
import com.insleton.admin.employee.model.Employee;
import com.insleton.admin.employee.service.EmployeeService;
import com.insleton.admin.image.service.spi.ImageResourceService;
import com.vteba.utils.common.MediaTypes;
import com.vteba.utils.id.ObjectId;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    private static final Logger LOGGER = LogManager.getLogger(EmployeeController.class);
    @Inject
    private EmployeeService employeeService;
    @Inject
    private PointService pointService;
    @Inject
    private ImageResourceService imageResourceService;

    @RequestMapping("/query")
    public List<Employee> query() {
        Employee employee = new Employee();
        employee.setName("yin");
        employeeService.queryTest(employee);

        return Lists.newArrayList(employee);
    }

    @RequestMapping("/list")
    public List<Employee> list() {
        Employee employee = new Employee();
        employee.setName("yin");
        List<Employee> employeeList = employeeService.list(employee);

        return employeeList;
    }

    @RequestMapping("/test")
    public List<Employee> test() {
        employeeService.test();

        List<Employee> employeeList = new ArrayList<>();

        return employeeList;
    }

    @RequestMapping("/test2")
    public List<Employee> test2() {
        employeeService.test2();

        List<Employee> employeeList = new ArrayList<>();

        return employeeList;
    }


    @RequestMapping("/save")
    public Object save() {
        Employee employee = new Employee();
        employee.setId(ObjectId.get().toString());
        employee.setName("尹大锤");

        employeeService.save(employee);

        return employee;
    }

    @RequestMapping("/saveBatch")
    public Object saveBatch() {
        Employee employee = new Employee();
        employee.setId(ObjectId.get().toString());
        employee.setName("尹大锤");

        employeeService.saveBatch(Collections.emptyList());

        return employee;
    }

    @ResponseBody
    @RequestMapping(value = "/testXe", produces = MediaTypes.PROTOBUF)
    public Object testXe() {
        Employee employee = new Employee();
        employee.setId(ObjectId.get().toString());
        employee.setName("尹大锤");

        // employeeService.saveBatch(Collections.emptyList());

        return employee;
    }

    @ResponseBody
    @RequestMapping(value = "/testSpring", produces = MediaTypes.JSON_UTF8)
    public Object testSpring() {
        Employee employee = new Employee();
        employee.setId(ObjectId.get().toString());
        employee.setName("尹大锤");

        pointService.test();

        return employee;
    }

    @ResponseBody
    @RequestMapping(value = "/testHibernate", produces = MediaTypes.JSON_UTF8)
    public Object testHibernate() {
        Employee employee = new Employee();
        employee.setId(ObjectId.get().toString());
        employee.setName("尹大锤");

        imageResourceService.test();

        return employee;
    }
}
